/*
 * @Author: Turump 
 * @Date: 2021-04-09 14:07:27 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-04-20 20:15:21
 * 播放粒子
 */

import { TaskBase } from "./TaskBase";
import TouchPlayAnimationTask from "./TouchPlayAnimationTask";

const { ccclass, property, requireComponent, menu } = cc._decorator;

@ccclass
@requireComponent(cc.ParticleSystem)
@menu("任务组件/播放粒子")
export default class PlayParticleTask extends TaskBase {

    @property({ displayName: "任务完成Emit事件", visible: false, override: true })
    doneEvent = ""

    @property({ displayName: "带音效", tooltip: "一次性音效" })
    withAudio = false;

    @property({ displayName: "音效资源", type: cc.AudioClip, visible() { return this.withAudio } })
    audioClip: cc.AudioClip = null;

    enableTask() {
        super.enableTask();

        if (this.node.getComponent(cc.ParticleSystem)) {
            this.node.getComponent(cc.ParticleSystem).resetSystem();
        }

        this.audioClip && (cc.audioEngine.playEffect(this.audioClip, false));
    }

    pauseTask() {
        super.pauseTask();
        if (this.node.getComponent(cc.ParticleSystem)) {
            this.node.getComponent(cc.ParticleSystem).stopSystem();
        }
    }

    resmueTask() {
        super.resmueTask();
        if (this.node.getComponent(cc.ParticleSystem)) {
            this.node.getComponent(cc.ParticleSystem).resetSystem();
        }
    }

    stopTask() {
        super.stopTask();
        if (this.node.getComponent(cc.ParticleSystem)) {
            this.node.getComponent(cc.ParticleSystem).stopSystem();
        }
    }
}
